<template>
  <!-- 奖品详情 -->
  <view class="content">
    <view class="content-header">
      <image :src="goodsDetails.prize.prizeAvatar" mode=""></image>
    </view>
    <view class="content-font">
      <text> 商品名称: <text
          style="font-size: 24rpx; font-weight: normal; margin-left: 20rpx;">{{goodsDetails.prize.prizeName}}</text></text>
      <text>所需积分: <text
          style="font-size: 24rpx; font-weight: normal;margin-left: 20rpx;">{{goodsDetails.prize.needIntegral}}</text></text>
      <text class="details">商品详情: <text
          style="font-size: 24rpx; font-weight: normal;margin-left: 20rpx;">{{goodsDetails.prize.prizeIntroduce}}</text></text>
    </view>

    <view class="btns">
      <u-button type="warning" size="small" text="线下自提" :disabled="btns" @click="showLine = true"></u-button>

      <u-button type="success" size="small" text="快递取货" :disabled="btns" @click= "shouunLine = true"></u-button>
    </view>



    <u-modal :show="showLine" :showCancelButton='true' :title="thisTitle" @confirm="confirmMethods"
      @cancel="showLine = false" width="250px"></u-modal>


   <u-modal :show="shouunLine" :showCancelButton='true' :title="thisTitle" @confirm="dizhiconfirm"
      @cancel="shouunLine = false" width="250px"></u-modal>

    <u-modal :show="show" :title="title" @confirm="confirm" confirmText="关闭" width="250px" :content='content'></u-modal>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        goodsDetails: {}, //商品信息

        showLine: false, //展示是否确定的弹框
        shouunLine:false,
        show: false, //展示线下自提的弹框
        title: '领奖地址', //弹框的标题
        thisTitle: '是否确定使用此方式兑换奖品',
        content: '', //线下地址
        btns:false
      };
    },
    onLoad(options) {
      this.goodsDetails = JSON.parse(decodeURIComponent(options.item))
      console.log(this.goodsDetails)
    },

    methods: {

      async confirmMethods() {
        this.showLine = false
        this.show = true
        const {
          data
        } = await uni.$http.get('/parameter/findAwardAddress')
        if (data.statusCode !== 200) {
          return uni.$u.toast('获取失败')
        } else {
          console.log(data)
          uni.$u.toast('获取成功')
          this.content = data.data.address
        }
      },
      // 线下地址弹框的关闭事件
    async  confirm() {
        this.show = false
        const obj = {
          awardType: 0,
          createTime: this.goodsDetails.createTime,
          id: this.goodsDetails.id,
          prizeId: this.goodsDetails.prizeId,
          mailAddress: this.goodsDetails.mailAddress,
          openId: this.goodsDetails.openId,
          orderNo: this.goodsDetails.orderNo,
          jobSeeker: uni.getStorageSync('userinfo'),
          prize: {
            createTime: this.goodsDetails.prize.createTime,
            exchangeNum: this.goodsDetails.prize.exchangeNum,
            id: this.goodsDetails.prize.id,
            isShelf: this.goodsDetails.prize.isShelf,
            needIntegral: this.goodsDetails.prize.needIntegral,
            prizeAvatar: this.goodsDetails.prize.prizeAvatar,
            prizeIntroduce: this.goodsDetails.prize.prizeIntroduce,
            prizeName: this.goodsDetails.prize.prizeName,
            prizeTotalNum: this.goodsDetails.prize.prizeTotalNum
          },
        }
        const { data } = await uni.$http.post('/prize/writeAwardType' , obj)
        console.log(data)
        if(data.statusCode !== 200) {
          return 
        }else {
          this.btns = true
          uni.$u.toast(data.message)
        }
      },
      sonEvent() {
        this.btns = true
      },
      dizhiconfirm(){
        this.shouunLine = false
        uni.navigateTo({
          url:'../reselectAddress/reselectAddress?item=' + JSON.stringify( this.goodsDetails)
        })
      }
    },
  }
</script>

<style lang="scss" scoped>
  .content {
    width: 100%;
    height: 100%;
    padding: 50rpx 50rpx 0 50rpx;
    box-sizing: border-box;

    .content-header {
      height: 500rpx;
      background-color: #FFFFFF;

      image {
        width: 100%;
        height: 100%;
      }
    }

    .content-font {
      display: flex;
      flex-direction: column;
      justify-content: space-around;

      text {
        margin: 20rpx 0;
        font-size: 28rpx;
        font-weight: 700;
      }

      .details {
        height: 200rpx;
        overflow: scroll;

      }
    }

    .btns {
      margin-top: 50rpx;
      display: flex;
      justify-content: space-around;
      align-items: center;

      /deep/.u-button.data-v-3bf2dba7 {
        width: 200rpx;
      }
    }
  }
</style>
